package com.danco.training.zaneuskaya.connection.dao.impl;

import java.util.List;

import org.hibernate.Criteria;
import org.hibernate.HibernateException;
import org.hibernate.Session;
import org.hibernate.criterion.Restrictions;

import com.danco.training.zaneuskaya.connection.dao.AbstractHibernateDao;
import com.danco.training.zaneuskaya.connection.dao.UserDao;
import com.danco.training.zaneuskaya.domain.User;

public class UserDaoImpl extends AbstractHibernateDao<User, Integer> implements UserDao{

	@Override
	public User read(Session session, Integer PK) throws HibernateException {
		return (User) super.read(session, User.class, PK);
	}

	@Override
	public List<User> readAll(Session session) throws HibernateException {
		return super.readAll(User.class, session);
	}

	@Override
	public User login(Session session, String login, String password) {
		Criteria cr = session
				.createCriteria(User.class)
				.add(Restrictions.eq("login", login))
				.add(Restrictions.eq("password", password));
		return (User) cr.uniqueResult();
	}


}
